package com.gotop.mapper.core.log.publisher;

import com.gotop.common.annotation.ApiLog;
import com.gotop.common.utils.ApplicationStringUtils;
import com.gotop.common.utils.WebUtil;
import com.gotop.entity.log.LogApi;
import com.gotop.mapper.core.log.event.ApiLogEvent;
import com.gotop.mapper.core.log.util.LogAbstractUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: cem
 * @description:
 * @author: superfish
 * @create: 2020-12-28 15:01
 **/
public class ApiLogPublisher {
    public ApiLogPublisher() {
    }

    public static void publishEvent(String methodName, String methodClass, ApiLog apiLog, long time) {
        HttpServletRequest request = WebUtil.getRequest();
        LogApi logApi = new LogApi();
        logApi.setType("1");
        logApi.setTitle(apiLog.value());
        logApi.setTime(String.valueOf(time));
        logApi.setMethodClass(methodClass);
        logApi.setMethodName(methodName);
        LogAbstractUtil.addRequestInfoToLog(request, logApi);
        Map<String, Object> event = new HashMap(16);
        event.put("log", logApi);
        ApplicationStringUtils.publishEvent(new ApiLogEvent(event));
    }

}
